#!/bin/bash

# 数据库配置
DB_USER="root"
DB_PASSWORD="123456"
DB_NAME="picking"
BACKUP_DIR="/disk2/mysql_backup"
DB_IP="127.0.0.1"
DB_PORT="3307"

# 备份文件名
TIMESTAMP=$(date +"%F")
BACKUP_FILE="${BACKUP_DIR}/${DB_NAME}-${TIMESTAMP}.sql"

# 备份数据库
/disk2/mysql_backup/mysqldump -u $DB_USER -p$DB_PASSWORD -h$DB_IP -P$DB_PORT $DB_NAME > $BACKUP_FILE

# 压缩备份文件（可选）
# gzip -f $BACKUP_FILE

# 修改脚本属性
# chmod +x backup_db.sh

# 添加定时任务每天凌晨1点备份
# 打开crontab编辑计划任务
# crontab -e
# 0 1 * * * /disk2/mysql_backup/backup_db.sh
